<?php

namespace app\admin\validate;

use think\Validate;

class Teacher extends Validate
{

    /**
     * 正则
     */
    protected $regex = ['format' => '^1\d{10}$'];

    /**
     * 验证规则
     */
    protected $rule = [
        'name'   => 'require|unique:Teacher',
        'mobile' => 'require|format|unique:Teacher'

    ];

    /**
     * 提示消息
     */
    protected $message = [
        'mobile.format' => '手机号格式不正确'
    ];

    /**
     * 字段描述
     */
    protected $field = [
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => ['name', 'mobile'],
        'edit' => ['name.unique'=>'require|unique:Teacher,name^id', 'mobile|unique:Teacher,mobile^id'],
    ];

    public function __construct(array $rules = [], $message = [], $field = [])
    {
        $this->field = [
            'name' => __('姓名'),
            'mobile' => __('手机号'),
        ];
        $this->message['name.format'] = '手机号格式不正确';
        parent::__construct($rules, $message, $field);
    }

}
